<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="预警状态：">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option v-for="item in statusList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="触发店铺名称：">
          <el-input v-model="formInline.shopName" placeholder="请输入触发店铺名称"></el-input>
        </el-form-item>

        <!-- <el-form-item label="预警序号：">
          <el-input
            v-model="formInline.id"
            placeholder="请输入预警序号"
            maxlength="19"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="预警类型：">
          <el-select v-model="formInline.type" placeholder="请选择">
            <el-option v-for="item in optionsType" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预警触发时间：">
          <el-date-picker v-model="date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <!-- <export-excel-button
          title="账单列表"
          action="/merchant/bill/v1/bill/export"
          :params="ExportParams"
        /> -->
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:warningstatus="{ scope }">
          <div class="yellow" v-if="scope.row.type==1||scope.row.type==2||scope.row.type==3">{{scope.row.typedict}}
          </div>
          <div class="red" v-else>{{scope.row.typedict}}</div>
        </template>
        <template v-slot:results="{ scope }">
          <div v-if="scope.row.result==''">-</div>
          <div v-if="scope.row.result!=''">{{scope.row.updateTime}} - {{scope.row.userName}}：{{scope.row.result}}</div>
        </template>
        <template v-slot:operate="{ scope }">
          <!-- <el-button @click="lookDetail(scope.row)">商家详情</el-button> -->
          <el-button @click="lookDetailtwo(scope.row)">预警详细</el-button>
          <!-- <el-button @click="handleFill(scope.row)" v-if="scope.row.status == 1">填写处理结果</el-button> -->
        </template>
      </ex-table>
    </div>
    <fillDetailDialog v-if="fillDialog" :id="id" :visible.sync="fillDialog" @success="_handleSuccess">
    </fillDetailDialog>
  </div>
</template>
<script>
  // components
  import {
    getwarningsList
  } from "@/api/warningComplaint";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import fillDetailDialog from './components/fillDetailDialog'
  export default {
    name: "warningList",
    components: {
      ExportExcelButton,
      fillDetailDialog,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        fillDialog: false,
        formInline: {
          merchantId: "",
          startTime: "", //开始时间
          endTime: "", //结束时间
          type: "", //
          merchantName: "", //商家名称
          shopName: "", //店铺名称
          id: "", //id(序号)
          status: '',
        },
        date: [],
        optionsType: [{
            id: "",
            value: "全部",
          },
          {
            id: "1",
            value: "经营风险",
          },
          // {
          //   id: "2",
          //   value: "申诉预警",
          // },
          {
            id: "3",
            value: "法人预警",
          },
          {
            id: "4",
            value: "司法风险",
          },
        ],
        statusList: [{
            id: "",
            value: "全部",
          },
          {
            id: "1",
            value: "未处理",
          },
          {
            id: "2",
            value: "已处理",
          },
        ],
        tableData: [],
        tableColumn: [
          {
            prop: "areaName",
            label: "管辖区域",
          },
          {
            prop: "createTime",
            label: "预警触发时间",
            width: 150
          },
          {
            label: "预警类型",
            slot: true,
            slotName: "warningstatus",
            width: 110
          },
          // { prop: "type", label: "预警分类", width: 120 },
          // { prop: "content", label: "预警内容", width: 220 },
          // { prop: "merchantName", label: "触发公司名称" },
          {
            prop: "shopName",
            label: "触发店铺名称"
          },
          {
            prop: "content",
            label: "预警事件"
          },
          {
            prop: "statusDict",
            label: "预警状态"
          },
          {
            label: "处理结果",
            slot: true,
            slotName: "results",
            width: 150
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate",
            width: 260
          },
        ],
        id: '',
      };
    },
    computed: {
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.formInline,
          startTime: this.date[0],
          endTime: this.date[1],
        };
        return params;
      },
    },
    mounted() {
      this.getList();
    },
    methods: {
      lookDetail(e) {
        console.log(e);
        this.$router.push({
          path: "/merchants/merchants-detail",
          query: {
            id: e.merchantId,
            name: e.merchantName,
          },
        });
      },
      lookDetailtwo(e) {
        console.log(e);
        this.$router.push({
          path: "/warningComplaint/warning-detail",
          query: {
            merchantId: e.merchantId,
            type: e.type,
          },
        });
      },
      //填写处理结果
      handleFill(row) {
        this.id = row.id
        this.fillDialog = true
      },
      search() {
        //搜索
        console.log(this.formInline);
        if (this.date) {
          this.formInline.startTime = this.date[0];
          this.formInline.endTime = this.date[1];
        }

        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        // this.formInline.fundFlow = ''
        // this.formInline.billType = ''
        this.date = [];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        //联动信息
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        getwarningsList(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;

            this.tableData = records.map((item) => {
              if (item.type == 1) {
                item.typedict = "经营风险";
              } else if (item.type == 2) {
                item.typedict = "申诉预警";
              } else if (item.type == 3) {
                item.typedict = "法人预警";
              } else if (item.type == 4) {
                item.typedict = "司法风险";
              } else {
                item.typedict = "-";
              }
              return item;
            });
            console.log("this.tableData", this.tableData);
            this.$refs.table.pageOptions.total = total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      _handleSuccess() {
        this.getList();
      },
    },
  };

</script>
<style lang="scss">
  .el-card-title {
    font-size: 20px;
  }

</style>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 40px;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }

  .red {
    color: #e64242;
  }

  .yellow {
    color: #e6a700;
  }

</style>
